#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/i2c.h>
#include <linux/err.h>
#include <linux/regmap.h>
#include <linux/slab.h>
#include <linux/version.h>

static struct i2c_board_info at24cxx_info[] ={
    {I2C_BOARD_INFO("at24cxx", 0x50)},
};

static struct i2c_client * at24c02_cline;

static int at24c02_dev_init(void)
{
    struct i2c_adapter * i2c_adap = i2c_get_adapter(1);
    printk("at24cxx_info len is %d",ARRAY_SIZE(at24cxx_info));

    if(i2c_adap == NULL) {
        printk("i2c_adap  is NULL");
        return -ENODEV;
    }
    
#if LINUX_VERSION_CODE <= KERNEL_VERSION(4,20,0)
    at24c02_cline = i2c_new_device (i2c_adap,at24cxx_info);
#else
    at24c02_cline = i2c_new_client_device (i2c_adap,at24cxx_info);
#endif
    i2c_put_adapter(i2c_adap);

    
    if(at24c02_cline)
        return 0;
    else
        return -ENODEV;

}

static void at24c02_dev_exit(void)
{
    i2c_unregister_device(at24c02_cline);
}

module_init (at24c02_dev_init);
module_exit (at24c02_dev_exit);
MODULE_LICENSE("GPL");

